import * as types from "./mutation-types";
import Api from "api/api";

const state = {
  problemList: {},
  problemLists: {},
  currentProblem: {}
};

const getters = {
  problemList: state => state.problemList,
  problemLists: state => state.problemLists,
  currentProblem: state => state.currentProblem
};

const actions = {
  // 问卷调查列表
  survrveyListUsingPOSTS({ commit }, param) {
    return Api.survrveyListUsingPOST(param).then(ret => {
      commit(types.UPDATE_PROBLEM_LIST, ret.data);
      return ret;
    });
  },
  // 问卷调查新增
  saveOrupdateSurveyUsingPOSTS({ commit },param) {
    return Api.saveOrupdateSurveyUsingPOST(param).then(ret => {
      return ret;
    })
  },
  // 问卷调查删除
  deleteSurveyUsingPOSTS({ commit }, param) {
    return Api.deleteSurveyUsingPOST(param).then(ret => {
      return ret;
    });
  },
  // 批量问卷调查删除
  batchDelProblem({ commit }, param) {
    return Api.delsUsingPOST_1(param).then(ret => {
      return ret;
    });
  }

};

const mutations = {
  [types.UPDATE_PROBLEM_LIST](state, payload) {
    state.problemList = payload;
  },
  [types.UPDATE_PROBLEM_LISTS](state, payload) {
    state.problemLists = payload;
  }
};

export default {
  state,
  getters,
  actions,
  mutations
};
